package tarea2test;

import java.util.Observable;
import java.util.Observer;

public class MainModel extends Observable {
	private float op1, op2;
	private float result;

	public MainModel(Observer observer) {
		this.addObserver(observer);
	}
	
	public void sum() {
		this.setResult(this.getOp1() + this.getOp2());
	}
	
	public void res() {
		this.setResult(this.getOp1() - this.getOp2());
	}
	
	public void mul() {
		this.setResult(this.getOp1() * this.getOp2());
	}
	
	public void div() throws ArithmeticException {
		this.setResult(this.getOp1() / this.getOp2());
	}

	public float getOp1() {
		return this.op1;
	}

	public void setOp1(float op1) {
		this.op1 = op1;
	}

	public float getOp2() {
		return this.op2;
	}

	public void setOp2(float op2) {
		this.op2 = op2;
	}

	public float getResult() {
		return result;
	}
	
	public String getResultString() {
		return Float.toString(result);
	}

	public void setResult(float result) {
		this.result = result;
		
		this.setChanged();
		this.notifyObservers();
	}

}
